package 课上练习0421_scala

/**
 * apply、unapply
 */
object Scala_02_case_class extends App {
  Point(1, 2)
}

class Point(var x: Int, var y: Int)

object Point {
  // 构建实例对象
  def apply(x: Int, y: Int): Point = new Point(x, y)

  //提取器，完成对象参数的提取，在模式匹配/偏函数中会用
  def unapply(arg: Point): Option[(Int, Int)] = {
    if (arg != null) Some(arg.x, arg.y) else None
  }
}


